using System;
using Taimila.Entify;
using Taimila.Entify.Attributes;

namespace Taimila.Entify.UnitTests
{
	[Entity(Version = 1.0)]
	public class ChildTestEntity : Entity
	{
		[EntityProperty(PersistentName = "Number")]
		public int Number
		{
			get;
			set;
		}
		
		private ParentTestEntity parent;
		private long? parentLazyLoadIdentifier;
		
		[EntityProperty(PersistentName = "Parent", Relationship = true)]
		public ParentTestEntity Parent
		{
			get
			{
				if(this.parentLazyLoadIdentifier == null)
				{
					return null;	
				}
				else if(this.parent == null)
				{
					this.parent = this.LazyLoadEntity<ParentTestEntity>(this.parentLazyLoadIdentifier);
					return this.parent;
				}
				else
				{
					return this.parent;	
				}
			}
			set
			{
				if(value == null)
				{
					this.parentLazyLoadIdentifier = null;
					this.parent = null;
				}
				else
				{
					this.parentLazyLoadIdentifier = value.GetEntityId();
					this.parent = value;
				}
			}
		}
	}
}
